package com.jinzhuo;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class router {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setVirtualHost("/jinzhuo");
        factory.setPassword("jinzhuo");
        factory.setUsername("jinzhuo");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        String exchangeName="routerExchange";
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT,true,false,false,null);

        String queName1="routerQueue1";
        String queName2="routerQueue2";
        channel.queueDeclare(queName1,true,false,false,null);
        channel.queueDeclare(queName2,true,false,false,null);
        channel.queueBind(queName1,exchangeName,"error");
        channel.queueBind(queName2,exchangeName,"info");

        String message="路由1发送错误消息";
        String message2="路由2发送信息";
        channel.basicPublish(exchangeName,"error",null,message.getBytes());
        channel.basicPublish(exchangeName,"info",null,message2.getBytes());

        channel.close();
        connection.close();
    }
}
